import axios from "axios";

// const url = "http://43.138.33.247:3000";
const url = "http://localhost:3000";

// 用户登录
export function getUser(username,password) {
  return axios({
    url:`${url}` + "/user/login?username="+`${username}` + "&password="+`${password}`,
    method:"get",
    // data:{
    //   username:username,
    //   password:password
    // }
  })
}

// 请求用户信息
export function getUserName(tokan) {
  return axios({
    url:`${url}` + "/user",
    method:"get",
    headers:{
      token:tokan
    }
  })
}


// 三级列表
export function getThreeLevelList() {
  return axios({
    url:`${url}` + "/categroy",
    method:"get",
  })
}

// 推荐商品
export function getRecommendSideber() {
  return axios({
    url:`${url}` + "/product/active",
    method:"get",
  })
}

// 商品详情
export function getCommodity(id) {
  return axios({
    url:`${url}` + "/categroy/info?categroyId=" + id,
    method:"get",
  })
}


// 添加到购物车
export function postAddShopping(tokan,obj) {
  return axios({
    url:`${url}` + "/shoppingCart/add",
    method:"post",
    headers:{
      'Content-Type': 'application/json; charset=utf-8', 
      token:tokan
    },
    data:obj
  })
}

// 查询购物车
export function getAddShopping(tokan,id) {
  return axios({
    url:`${url}` + "/shoppingCart/select?userId=" + id,
    method:"get",
    headers:{
      token:tokan
    },
  })
}

// 立即购买商品
export function postBuy(tokan,productId,skuId,nums,orders) {
  return axios({
    url:`${url}` + "/order/add?productId=" + productId + "&skuId=" + skuId+ "&nums=" + nums,
    method:"post",
    headers:{
      'Content-Type': 'application/json; charset=utf-8', 
      token:tokan
    },
    data:orders
  })
}

// 添加收货地址
export function postAddress(tokan,obj) {
  return axios({
    url:`${url}` + "/user",
    method:"post",
    headers:{
      'Content-Type': 'application/json; charset=utf-8', 
      token:tokan
    },
    data:obj
  })
}

// 查询收货地址
export function getUserAddress(tokan,id) {
  return axios({
    url:`${url}` + "/user/selectUserAddr?userId=" + id,
    method:"get",
    headers:{
      token:tokan
    },
  })
}

